package com.imageim.yimirror.common.ui.analysis;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;

import com.imageim.yimirror.R;
import com.imageim.yimirror.bean.analysisPhoto.PointBean;
import com.imageim.yimirror.common.ui.GlideUtils;
import com.imageim.yimirror.common.ui.drawbody.BodyLineView;
import com.makeramen.roundedimageview.RoundedImageView;

import java.util.Map;

/**
 * Created by Bruce.Zhou on 2018/6/27 17:15.
 * Email: 907160968@qq.com
 * 历史分析界面身线图
 */

public class HistoryBodyLineView extends RelativeLayout {

    public HistoryBodyLineView(Context context) {
        super(context);
        init(context);
    }

    public HistoryBodyLineView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public HistoryBodyLineView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private RoundedImageView ivPhoto;
    private BodyLineView bodyLineView;


    private void init(Context context) {
        View root = View.inflate(context, R.layout.layout_history_analysis_photo_view, this);
        bodyLineView = root.findViewById(R.id.body_line_view);
        ivPhoto = root.findViewById(R.id.iv_photo);
    }


    public void show() {
        setVisibility(View.VISIBLE);
        bodyLineView.setCanDraw(true);
    }


    public void setPhoto(String photoPath) {
        GlideUtils.display(ivPhoto, photoPath);
    }

    public void setPhoto(Bitmap bitmap) {
        ivPhoto.setImageBitmap(bitmap);
    }


    public void hideBodyLine() {
        bodyLineView.setVisibility(View.INVISIBLE);
        bodyLineView.setCanDraw(false);
    }

    public void showBodyLine() {
        bodyLineView.setVisibility(View.VISIBLE);
        bodyLineView.setCanDraw(true);
    }

    public void setBodyData(Map<String, PointBean> points) {
        if (points != null) {
            bodyLineView.initData(points);
        }
    }

    /**
     * 是否显示轨迹点
     *
     * @param drawIndicator
     */
    public void setDrawIndicator(boolean drawIndicator) {
        if (bodyLineView != null) {
            bodyLineView.setDrawIndicator(drawIndicator);
        }
    }

    /**
     * 设置坐标转换比率 需要在setBodyData方法前调用
     * 相对于1080*1920  智能分析 0.35f
     */
    public void setRate(float rate) {
        bodyLineView.setCurrentRate(rate);
    }

    public void destory() {
        removeAllViews();
        stopBodyLineView();
    }

    public void stopBodyLineView() {
        if (bodyLineView != null) {
            bodyLineView.stop();
        }
    }


}